<?php

session_start();
include_once '../conf/conf.php';
$id = $_SESSION['id'];
$name = $_SESSION['name'];
$dob = $_SESSION['dob'];
$today = date("Y-m-d");
$datea = strtotime("$dob");
$dateb = strtotime("$today");
      $sql = "SELECT encount.enc_id,encdate, weight, height FROM encount, clinical WHERE encount.id = '$id' AND encount.enc_id = clinical.enc_id ORDER BY encdate DESC";
      $res = mysqli_query($con, $sql) or die("sorry, database is updating...");
$htdata = array();
$wtdata = array();
while ($row = mysqli_fetch_array($res)) {
  $date = $row['encdate'];
  $f_date = strtotime($date);
  $htdata[] = array('', $f_date, $row['height']);
  $wtdata[] = array('', $f_date, $row['weight']);  
}
mysqli_free_result($res);
mysqli_close($con);

include('phplot.php');

//Define the object
$graph = new PHPlot(492, 600);
$graph->SetImageBorderType('plain');
$graph->SetPrintImage(0);
$graph->SetTitle("Weight & Height chart");

$graph->SetPlotAreaPixels(50,40,480,180);
$graph->SetPlotAreaWorld(NULL, NULL, NULL, NULL);
//$graph->SetXTitle('Date');
$graph->SetYTitle('Height (cm)');
$graph->SetDataValues($htdata);
$graph->SetPlotType('linepoints');
$graph->SetDataType('data-data');
//$graph->SetXLabelAngle(90);
//$graph->SetXLabelType('time', '%Y-%m-%d');
$graph->SetDataColors(array('maroon'));
//$graph->SetXTickIncrement(2623000);
$graph->SetYTickIncrement(10);
$graph->SetPointSizes(8);
$graph->SetPlotAreaWorld($datea, 40, $dateb, NULL);
$graph->SetDrawXGrid(TRUE);
$graph->SetXTickLabelPos('none');
$graph->SetXTickPos('none');
$graph->DrawGraph(); 

$graph->SetPlotAreaPixels(50,200,480,520);
$graph->SetXTitle('Date');
$graph->SetYTitle('Weight (kg)');
$graph->SetDataValues($wtdata);
$graph->SetPlotType('linepoints');
$graph->SetDataType('data-data');
$graph->SetXLabelAngle(90);
$graph->SetXLabelType('time', '%Y-%m-%d');
$graph->SetDataColors(array('red'));
$graph->SetXAxisPosition(0,0);
$graph->SetDrawXGrid(TRUE);
//$graph->SetXTickIncrement(2623000);
$graph->SetYTickIncrement(5);
$graph->SetPointSizes(8);
$graph->SetPlotAreaWorld($datea, 0, $dateb, NULL);
//$graph->SetXTickLabelPos('none');
//$graph->SetXTickPos('none');
$graph->DrawGraph();

$graph->PrintImage();
?>